/*
Brick And Blast, a crossplatform breakout game.
 Copyright (C) 2008-2010 Julien CLEMENT (andematunum@gmail.com)
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 

*/

#ifndef _Collision_h_
#define _Collision_h_

/**
* file   Collision.h
* date   Lun 28 déc 2009 22:44:36 CET
* brief  TODO
*/

#include "GameObject.h"

#include <iostream>
using namespace std;

class Collider;

class Collision {
public:
  /** Constructor used for the comparator. */
  Collision () {
  }
  Collision(GameObject* first, GameObject* second, ColliderData* data)
    : data_(data) {
    // Sort by address to simplify the equality test
    if (first < second) {
      first_ = first;
      second_ = second;
    }
    else {
      first_ = second;
      second_ = first;
    }
  }
  GameObject* get_first () {
    return first_;
  }
  GameObject* get_second () {
    return second_;
  }
  ColliderData* get_data () {
    return data_;
  }

  void handle () {
    first_->handle_collision(second_, *data_);
    first_->calculate_next_pixel_position();
    second_->handle_collision(first_, *data_);
    second_->calculate_next_pixel_position();
    first_->handle_game_area_collisions();
    second_->handle_game_area_collisions();
  }
  
  bool operator() (Collision* c1, Collision* c2) const {
    // Simplified because the 2 addresses are sorted.
    return ((c1->get_first() == c2->get_first()) &&
            (c1->get_second() == c2->get_second()));
  }
  
private:
  GameObject* first_;
  GameObject* second_;
  ColliderData* data_;
};

#endif

